package com.Oct_TwentySix;

public class Solution938 {
    
    public int rangeSumBST(TreeNode root, int low, int high) {
        if (root==null) return 0;
        if (root.val<=high&&root.val>=low)
        {
            return root.val+rangeSumBST(root.left,low,high)+rangeSumBST(root.right,low,high);
        }else if (root.val<low)
        {
            return rangeSumBST(root.right,low,high);
        }else {
            return rangeSumBST(root.left,low,high);
        }
    }

    public static class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
      }
  }
}
